<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    body{
        padding: 0;
        margin: 0;
    }
    .box{
        width: 100%;
        height: 100vh;
    }
</style>
<body>
    <div class="box" id="box">
        <button>点击变颜色</button>
    </div>
</body>
</html>
<script>
    //获取button按钮
    var bjcolor = document.querySelector('button')
    //获取到box
    var box = document.getElementById('box')
    var flag = false;
    bjcolor.addEventListener('click',function(){
        flag = !flag;
        flag?box.style.background = '#000':box.style.background = '#fff'
        let color = flag?'黑色':'白色'
        bjcolor.innerText = color
    })
</script>